package com.example.demo.utils;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class R<T> {

    @ApiModelProperty(value = "状态码",example = "200")
    private Integer code;

    @ApiModelProperty(value = "状态码信息",example = "成功")
    private String msg;

    private T data;

    public static R success() {
        return new R(200, "操作成功",null);
    }

    public static <T> R<T> success(String msg, T data) {
        return new R(200, msg, data);
    }

    public static R error(String msg) {
        return new R(500, msg, null);
    }

    public static R error() {
        return new R(500,"操作失败",null);
    }

    public static R to(boolean b){
        return b ? R.success() : R.error();
    }

}
